import View404 from '@/views/no-found.vue'
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
// import { useUserStore } from "@/store/modules/user"
const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    //这里还需要判断是那个身份登录的！！！
    redirect: (to) => {
      //我觉的登录的时候将初始数据保存一份到本地存储，之后立马删了
      console.log(to);
      // const userStore = useUserStore()
      // let loginType = userStore.signType//这里可以判断一下登录时状态，用于下面的跳转

      const signType = to.query?.identity
      if (signType === 'boss') {
        return "/boss/home"
      } else if (signType === 'geek') {
        return "/geek/home"
      } else {
        return "/user"
      }
    },
  },
  {
    path: '/geek',
    redirect: "/geek/home",
    component: () => import("@/views/GEEK/index.vue"),
    children: [
      {
        path: "home",
        component: () => import("@/views/GEEK/Home/index.vue"),
        meta: {
          page: 1001,
          title: "首页"
        }
      },
      {
        path: "job-recommend",
        component: () => import("@/views/GEEK/Job-Recommend/index.vue"),
        meta: {
          page: 1002,
          title: "推荐职位"
        }
      },
      {
        path: "Message",
        component: () => import("@/views/GEEK/Message/message.vue"),
        meta: {
          page: 1005,
          title: "消息"
        }
      },
      {
        path: 'resume',
        component: () => import("@/views/GEEK/Resume/geek-resume.vue"),
        meta: {
          page: 1006,
          title: "简历"
        }
      },
      {
        path: "center",
        component: () => import("@/views/GEEK/Center/center.vue"),
        meta: {
          page: 1007,
          title: "个人中心"
        }
      },
      {
        path: "interview",
        component: () => import("@/views/GEEK/Interview/interview.vue"),
        meta: {
          page: 1003,
          title: "面试"
        },
        redirect: "/geek/interview/aiInterview",
        children: [
          {
            path: "aiInterview",
            components: {
              aiInterview: () => import("@/views/GEEK/Interview/interviewChildren/aiInterview.vue"),
              experienceShare: () => import("@/views/GEEK/Interview/interviewChildren/experienceShare.vue")
            },
          },
          {
            path: "interviewExperience",
            components: {
              interviewExperience: () => import("@/views/GEEK/Interview/interviewChildren/interviewExperience.vue"),
              experienceRelease: () => import("@/views/GEEK/Interview/interviewChildren/experienceRelease.vue")
            }
          }
        ]
      },
      {
        path: '/interviewAI',
        meta: {
          page: 1004,
          title: "AI面试"
        },
        component: () => import("@/views/GEEK/InterviewAI/InterviewAI.vue")
      },
      {
        path: '/interviewResult',
        meta: {
          page: 1008,
          title: "面试结果"
        },
        component: () => import("@/views/GEEK/InterviewAI/InterviewResult.vue")
      },
      {
        path: 'ai',
        component: () => import("@/views/GEEK/AI/index.vue"),
        meta: {
          page: 1009,
          title: "AI"
        }
      }
    ]
  },
  {
    path: '/guide',
    /* 路由独享的守卫 */
    beforeEnter: (to, from, next) => {
      // 下面我只是做了一个跳转 控制
      if (to.query.identity === "geek") {
        next({ name: "geek", hash: to.hash })
      } else if (to.query.identity === "boss") {
        next({ name: "boss" })
      } else {
        next()
      }
    },
    component: () => import("@/views/Guide/guide.vue"),
    meta: {
      hidden: true,
      title: '填写信息'
    },
    children: [
      {
        name: 'geek',
        path: "guide-1",
        component: () => import("@/views/Guide/guideView/guide-1.vue"),
        meta: {
          page: 1
        }
      },
      {
        path: "guide-2",
        component: () => import("@/views/Guide/guideView/guide-2.vue"),
        meta: {
          page: 2
        }
      },
      {
        path: "guide-3",
        component: () => import("@/views/Guide/guideView/guide-3.vue"),
        meta: {
          page: 3
        }
      },
      {
        path: "guide-4",
        component: () => import("@/views/Guide/guideView/guide-4.vue"),
        meta: {
          page: 4
        }
      },
      {
        path: "guide-5",
        component: () => import("@/views/Guide/guideView/guide-5.vue"),
        meta: {
          page: 5
        }
      },
      {
        path: "guide-6",
        component: () => import("@/views/Guide/guideView/guide-6.vue"),
        meta: {
          page: 6
        }
      },
      {
        name: 'boss',
        path: "boss",
        component: () => import("@/views/Guide/guideView/guide-boss.vue")
      }
    ]
  },
  {
    path: "/user",
    component: () => import("@/views/User/loginRegister.vue"),
    meta: {
      hidden: true,
      title: '登录注册'
    }
  },
  {
    path: "/form",
    component: () => import("@/components/formitems/index.vue")
  },
  {
    path: '/boss',
    redirect: "/boss/home",
    component: () => import("@/views/BOSS/index.vue"),
    children: [
      {
        path: "home",
        component: () => import("@/views/BOSS/Home/boss-home.vue"),
        meta: {
          page: 1001,
          title: "首页"
        }
      },
      {
        path: 'center',
        component: () => import("@/views/BOSS/BossCenter/index.vue"),
        meta: {
          page: 1002,
          title: "个人中心"
        }
      },
      {
        path: "chat",
        component: () => import("@/views/BOSS/Chat/chat.vue"),
        meta: {
          page: 1003,
          title: "聊天"
        }
      },
      {
        path: "geek-recommend",
        component: () => import("@/views/BOSS/GeekRecommend/index.vue"),
        meta: {
          page: 1004,
          title: "推荐工作"
        }
      },
      // {
      //   path: "more",
      //   component: () => import("@/views/BOSS/More/more.vue"),
      //   meta:{
      //     page:1005,
      //     title:"更多"
      //   }
      // },
      {
        path: "pos-manage",
        component: () => import("@/views/BOSS/PosManage/manage.vue"),
        meta: {

          page: 1006,
          title: "职位管理"
        }
      },
      // {
      //   path: "search",
      //   component: () => import("@/views/BOSS/Search/index.vue"),
      //   meta:{
      //     page:1007,
      //     title:"搜索"
      //   }
      // }
    ]
  },
  {
    path: "/zwh",
    component: () => import("@/views/BOSS/Search/index.vue"),
  },
  {
    path: "/elem",
    component: () => import("@/components/formitems/el-index.vue")

  },
  //路由没有匹配上到404界面
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: View404,
    meta: { hidden: true },
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),//import.meta.env.BASE_URL 为 vite.config.js 中根路径base字段
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),//设置滚动行为。当导航到一个新的路由时，这个函数决定了页面应该滚动到哪个位置。
})

//这里得去规定一个全局路由守卫，不同账号的权限不同，不能访问响应的界面中去

router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title as string
  next()
})


/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router
